﻿using System;
using System.Diagnostics;

namespace CompactMapper.Orm.Util
{
    public class TimedTrace : IDisposable
    {
        private readonly string _task;
        private readonly Stopwatch _stopwatch;

        public TimedTrace(String task)
        {
            _task = task;
            _stopwatch = new Stopwatch();
            _stopwatch.Start();
        }


        public void Dispose()
        {
            _stopwatch.Stop();
            Trace.WriteLine(String.Format("{0} took {1}", _task,
                                          TimeSpan.FromTicks(_stopwatch.ElapsedTicks).TotalMilliseconds));
        }
    }
}